package com.qef.com.mmovie.mvp.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.avos.avoscloud.AVObject;
import com.orhanobut.logger.Logger;
import com.qef.com.mmovie.App;
import com.qef.com.mmovie.R;
import com.qef.com.mmovie.base.BaseRecycerViewAdapter;
import com.qef.com.mmovie.img.ImageLoader;
import com.qef.com.mmovie.utils.DateUtil;

import org.w3c.dom.Text;

import java.util.List;

/**
 * Created by guangjiego on 2017/5/27.
 */

public class CommentAdapter extends BaseRecycerViewAdapter<AVObject, CommentAdapter.MyHolder> {
    public CommentAdapter(Context context, List<AVObject> list) {
        super(context, list);
    }

    @Override
    public MyHolder getCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyHolder(inflater.inflate(R.layout.comment, parent, false));
    }

    @Override
    public void getBindViewHolder(MyHolder holder, int position) {
        ImageLoader.getInstance().displayCricleImage(App.getInstance(), list.get(position).get("userHead").toString(), holder.ivHead);
        holder.tvName.setText(list.get(position).get("userName").toString());
        holder.tvContent.setText(list.get(position).get("content").toString());
        holder.tvTime.setText(DateUtil.gstToData(list.get(position).getCreatedAt().toString()));
    }

    class MyHolder extends RecyclerView.ViewHolder {
        ImageView ivHead;
        TextView tvName;
        TextView tvContent;
        TextView tvTime;

        MyHolder(View itemView) {
            super(itemView);
            ivHead = (ImageView) itemView.findViewById(R.id.user_head);
            tvName = (TextView) itemView.findViewById(R.id.tv_name);
            tvContent = (TextView) itemView.findViewById(R.id.tv_content);
            tvTime = (TextView) itemView.findViewById(R.id.tv_time);
        }
    }
}
